package com.ljx.NoteBody.common;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.sql.SQLIntegrityConstraintViolationException;

/**
 * 全局异常处理
 * @ControllerAdvice配合@ExceptionHandler用于捕获Controller中抛出的指定类型的异常，从而达到不同类型的异常区别处理的目的。
 */

@ResponseBody
@ControllerAdvice(annotations = {RestController.class, Controller.class})
public class GlobalExceptionHandler {

    // @ExceptionHandler(xxx.class)：表示需要捕获的异常类名
    @ExceptionHandler(MyException.class)
    public R<String> MyExceptionHandler(MyException e){

        return R.error(e.getMessage());
    }




}
